<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>二维码核验</title>
    <style>
        body {
          font-family: Arial, sans-serif;  
            margin: 0;  
            padding: 0;  
            background-color: #f0f0f0;  
            color: #000000;
            font-size: 14px;
            line-height: 1.5;
            text-align: center;
            box-sizing: border-box;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            -webkit-text-size-adjust: none;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            -webkit-touch-callout: none;
            
        }
        
        #myForm {
            display: flex;  
            flex-direction: column;  
            margin: 0 auto;  
            padding: 20px;  
            border: 1px solid #ccc;  
            border-radius: 5px;  
            background-color: #fff; 
            text-align: center;
            width: 400px;
        }

        input[type=text] {
            width: 300px;
            height: 40px;
            padding: 5px;
            margin-bottom: 20px;
            border-radius: 5px;
            box-sizing: border-box;
            align-self: center;
            border: 1px solid #ccc;
            outline: none;

            -webkit-border-radius: 5px;
            -webkit-box-sizing: border-box;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            -webkit-touch-callout: none;
          
        }
        
        input[type=submit] {
            background-color: dodgerblue;
            color: white;
            padding: 10px 20px;
            cursor: pointer;
            border-radius: 5px;
            align-self: center;
            border: 1px solid #ccc;
            outline-color: invert;

            -webkit-border-radius: 10px;
            -webkit-box-sizing: border-box;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            -webkit-touch-callout: none;
        }
        
        #result {
            margin-top: 30px;
            color: #000000;
            font-size: medium;
        }
    </style>

<audio id="sound1" src="sound/1.wav" preload="auto"></audio>
<audio id="sound2" src="sound/2.wav" preload="auto"></audio>
<audio id="sound3" src="sound/3.wav" preload="auto"></audio>



<script src="js/jquery.min.js"></script>
<script>

    $(document).ready(function(){
  $("#myForm").submit(function(e){
    e.preventDefault(); // 阻止表单默认的提交行为

    var formData = $(this).serialize();

    $.ajax({
      url: 'search.php',
      type: 'POST',
      data: formData,
      dataType: 'json',
      success: function(data){
        //数据库是否提交成功
        var state = '未操作';
        if(data.state === true){
          state = '提交成功';
        }else if(data.state === false){
          state = '提交失败';
        }
        //查询是否重复入场
        var repeated = 0;
        if(data.repeated === true){
          repeated = '重复入场';
        }else if(data.repeated === false){
          repeated = '首次入场';
        }
        if(data.error === false){ 
          $('#result').text('欢迎回来，' + data.name + '，您的ID是' + data.id + ', 数据库' + state + '，' + repeated);
        } else {
          $('#result').text('核验失败，票号不存在');
        }
        if(data.error === true){
          $('#sound3')[0].play();
          console.log('sound3已播放');
        }else if(data.error === false){
          if(data.repeated === true){
            $('#sound2')[0].play();
            console.log('sound2已播放');
          }else if(data.repeated === false){
            $('#sound1')[0].play();
            console.log('sound1已播放');

          }
        }
      },
      error: function(error){
        console.log("发生错误：" + JSON.stringify(error));
      }
    });
    //清空表单
    $('#myForm')[0].reset();
  });
});

</script>

</head>
<body>
  <div id="header">
    <h1>星萌检票姬WEB版</h1>
    <h2>请在下方输入二维码数据</h2>
  </div>


<form id="myForm">
  <input type="text" name="ticket_data" placeholder="在此输入二维码数据">
  <input type="submit" value="核验">
</form>

<div id="result"></div>
<p>本项目由<a href="https://gitee.com/miku_cute/cutestar-ticket-checker-web">Cutemiku</a>维护</p>
<p style="color: gray;">beta测试版，请勿用于生产环境</p>
<p style="color: gray;">beta0.0.1</p>

</body>
</html>